Lasso Soft Inc. > Home

[regexp->forEachMatch]

Linkregexp->forEachMatch
AuthorBrad Lindsay
CategoryString
Version9.x
LicensePublic Domain
Posted06 Aug 2012
Updated06 Aug 2012
More by this author...

Description

The [regexp->forEachMatch] method allows you to iterate over each match in your regular expression to do complex replacements. It also automatically calls the [regexp->appendTail] at the end that is easy to forget.

Sample Usage

local(matcher) = regexp(-find=`(?i)[aeiou]`, -input='Whoa, this is heavy!')
#matcher->forEachMatch => {
    #1->appendReplacement(string_upperCase(#1->matchString(0)))
}
#matcher->output
// Outputs: WhOA, thIs Is hEAvy!


local(no_vowels) = regexp(-find=`(?i)[aeiou]`, -input='Lager, sir, is regal')->forEachMatch => {
    #1->appendReplacement('_')
}&output
// #no_vowels no the following string: 'L_g_r, s_r, _s r_g_l'

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define regexp->forEachMatch => {
    while(.find) => { givenBlock(self) } 
    .appendTail
}

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft